import { LogLevel, SystemType, LogAppender } from '../../../constants/log';
/**
 * 验证查询表单字段是否合法
 * @param {object} form 查询表单
 */
export function validateSearchForm(form) {
  if (!form.start) return '请选择查询开始时间';
  if (!form.end) return '请选择查询结束时间';

  return null;
}

/**生成系统日志级别下拉列表可选数据*/
export function generateLevelSelectorData() {
  const result = [];
  Object.values(LogLevel).forEach(level => {
    result.push({ value: level, label: getLevelDisplay(level) });
  });

  return result;
}

/**
 * 获取日志级别显示内容
 * @param {string} level 日志级别
 */
export function getLevelDisplay(level) {
  switch (level) {
    case LogLevel.Trace:
      return '追溯';
    case LogLevel.Debug:
      return '调试';
    case LogLevel.Info:
      return '信息';
    case LogLevel.Warn:
      return '警告';
    case LogLevel.Error:
      return '错误';
    case LogLevel.Fatal:
      return '致命错误';
    default:
      return '未知级别';
  }
}

/**
 * 获取日志级别显示颜色
 * @param {string} level 日志级别
 */
export function getLevelColor(level) {
  switch (level) {
    case LogLevel.Trace:
      return '#BBBBBB';
    case LogLevel.Debug:
      return '#10aeff';
    case LogLevel.Info:
      return '#07c160';
    case LogLevel.Warn:
      return '#ffc300';
    case LogLevel.Error:
      return '#fa5151';
    case LogLevel.Fatal:
      return '#fa5151';
    default:
      return '#FFFFFF';
  }
}

/**生成系统类型下拉列表可选数据*/
export function generateSystemTypeSelectorData() {
  const result = [];
  Object.values(SystemType).forEach(type => {
    result.push({ value: type, label: getSystemTypeDisplay(type) });
  });

  return result;
}

/**
 * 获取系统类型显示信息
 * @param {string} system 系统类型
 */
export function getSystemTypeDisplay(system) {
  switch (system) {
    case SystemType.Master:
      return '系统主服务';
    case SystemType.Log:
      return '日志微服务';
    case SystemType.MqttAuth:
      return 'Mqtt认证服务';
    case SystemType.MqttBrokerLeak1000:
      return 'MqttBrokerLeak1000';
    default:
      return '未知系统类型';
  }
}

/**生成日志类别下拉列表可选数据*/
export function generateAppenderSelectorData() {
  const result = [];
  Object.values(LogAppender).forEach(appender => {
    result.push({ value: appender, label: getAppenderDisplay(appender) });
  });

  return result;
}

/**
 * 获取日志类别显示信息
 * @param {string} appender 日志类别
 */
export function getAppenderDisplay(appender) {
  switch (appender) {
    case LogAppender.Init:
      return '初始化模块';
    case LogAppender.User:
      return '用户模块';
    case LogAppender.Auth:
      return '验证模块';
    case LogAppender.Role:
      return '角色模块';
    case LogAppender.Guard:
      return '权限管理模块';
    case LogAppender.Area:
      return '区域管理模块';
    case LogAppender.Factory:
      return '厂房模块';
    case LogAppender.Device:
      return '设备模块';
    case LogAppender.DeviceType:
      return '设备类型模块';
    case LogAppender.Package:
      return '包模块';
    case LogAppender.Log:
      return '日志模块';
    case LogAppender.Upgrade:
      return '升级模块';
    default:
      return '未知类别';
  }
}
